package com.spsy.order.controller;

import com.alibaba.fastjson2.JSON;
import com.spsy.api.common.AddOrderVo;
import com.spsy.api.common.NotifyOrderVo;
import com.spsy.common.core.domain.R;
import com.spsy.order.api.OrderApi;
import com.spsy.order.domain.OrderInfo;
import com.spsy.order.service.IOrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: liuzhiping
 * @date: 2025/11/4 18:08
 **/
@RestController
@Slf4j
public class OrderApiController implements OrderApi {



    @Autowired
    private IOrderInfoService iOrderInfoService;


    @Override
    public R NotifyOrder(NotifyOrderVo vo) throws Exception {


        log.info("vo:{}", JSON.toJSONString(vo));


        long status = 0;

        if(vo.getStatus().equals("x")){
            status = 1;
        }

        //1秒杀
        int updateCount = this.iOrderInfoService.updateOrderInfoByOrderNo(OrderInfo.builder().orderSn(vo.getOrderId()).orderStatus((status)).build());

        //睡5秒
        Thread.sleep(50000);


        //修改订单状态
        log.info("updateCount:{}",updateCount);

        return R.ok("succcss");
    }
}
